import functools

from flask import session, current_app, jsonify, g

from info.response_code import RET


def  do_ranklist_class(index):

    if index == 0:
        return 'first'
    elif index ==1:
        return 'second'
    elif index == 2:
        return 'third'
    else:
        return ''

# 查询当前登录用户对象的代码在多个视图函数中都需要使用，我们可以使用装饰器将其封装
def get_user_info(view_func):
    @functools.wraps(view_func)
    def  wrapper(*args, **kwargs):
        user_id = session.get("user_id")
        from info.models import User
        user = None  # type: User
        if user_id:
            try:
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
                return jsonify(errno=RET.DBERR, errmsg="查询用户对象异常")
        g.user = user
        result=view_func(*args, **kwargs)
        return result
    return wrapper